<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<div id="main">
	<div id="search">
		<form action="<? echo base_url();?>main/search" method="POST" name="search_form" id="search_form" class="form-search">
			<p><input type="text" name="search" value="" id="search_text" class="search-query"/><input type="submit" value="Search" class="btn btn-large btn-primary"/></p>
		</form>
		<p><a href="<? echo base_url();?>history" class="btn">검색 기록</a> <a href="<? echo base_url();?>user/logout" class="btn">로그아웃</a></p>
	</div>
	<div id="map">
	  
	</div>
</div>
<script type="text/javascript" charset="utf-8">
//from http://code.google.com/intl/en/apis/maps/documentation/javascript/examples/geocoding-simple.html
function initialize() {
	geocoder = new google.maps.Geocoder();
	var myLatlng = new google.maps.LatLng(36,127);
	var myOptions = {
		zoom: 8,
		center: myLatlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	google_map = new google.maps.Map(document.getElementById("map"), myOptions);
}

function codeAddress() {
	var address = $("#search_text").val();
	geocoder.geocode( { 'address': address}, function(results, status) {
		if (status == google.maps.GeocoderStatus.OK) {
			google_map.setCenter(results[0].geometry.location);
			var marker = new google.maps.Marker({
				map: google_map, 
				position: results[0].geometry.location,
				title : address
			});
		} else {
			alert("error : " + status);
		}
	});
}
$(document).ready(function() {
	$("#search_form").submit(function(){
			codeAddress();
			$.post('<? echo base_url();?>history/log', {'data': $("#search_text").val() }, function(data) {
  				$('.result').html(data);
			});
			return false;
		}
	);
	initialize();
	$( "#search_text" ).autocomplete({
		source: "<? echo base_url();?>history/autocomplete",
		select: function( event, ui ) {
			$("#search_text").val(ui.item.id);
		}
	});
	
	
	
});




</script>